package com.it.controller;

import com.it.pojo.Login;
import com.it.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/petapp")
@Api("配置controller的测试接口")
public class LoginController {
    @Resource
    LoginService loginService;
    //查询用户是否已注册
    @RequestMapping(value = "/whether/{phone}")
    @ApiOperation("查看用户是否已经注册手机号")
    public boolean whether(@PathVariable(value = "phone") String phone){
        Login login = loginService.SignLogin(phone);
        return login!=null;
    }
    //登录
    @RequestMapping(value = "/SignLogin/{phone}/{pwd}")
    @ApiOperation("用户手机号登录")
    public boolean SignLogin(@PathVariable(value = "phone") String phone,
                             @PathVariable(value = "pwd") String pwd){
        try {
            Login login = loginService.SignLogin(phone);
            if(login==null||login.getPassword().equals(pwd)){
                return false;
            }
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
    //邮箱登录
    @ApiOperation("用户邮箱登录")
    @RequestMapping(value = "/EmailLogin/{email}/{pwd}")
    public boolean EmailLogin(@PathVariable(value = "email") String email,
                              @PathVariable(value = "pwd") String pwd){
        try {
            Login login = loginService.EmailLogin(email);
            if(login==null||login.getPassword().equals(pwd)){
                return false;
            }
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}